package com.bishe.bishe.dao.mapper;

import com.bishe.bishe.pojo.Comments;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface CommentMapper {
    @Results({
            @Result(property = "commentId",column = "comment_id"),
            @Result(property = "commentContent",column = "comment_content"),
            @Result(property = "orders",column = "comment_order_id",one = @One(select = "com.bishe.bishe.dao.mapper.OrderMapper.finddetailById")),
    })
    @Select("select * from comment c,feedback f where f.feedback_comment_id=c.comment_id ")
    List<Comments> findall();

    @Results({
            @Result(property = "commentId",column = "comment_id"),
            @Result(property = "commentContent",column = "comment_content"),
            @Result(property = "orders",column = "comment_order_id",one = @One(select = "com.bishe.bishe.dao.mapper.OrderMapper.finddetailById")),
    })
    @Select("select * from comment where comment_id=#{commentId}")
    List<Comments> findById(Integer commentId);


    @Insert("insert into comment(comment_id,comment_content,comment_order_id,comment_state) value(null,#{comments.commentContent},#{comments.orders.orderId},#{comments.commentState})")
    @Options(useGeneratedKeys=true, keyProperty="comments.commentId", keyColumn="comment_id")
    int insert(@Param("comments") Comments comments);

    @Update("update comment set comment_state='已回复' where comment_id=#{commentId}")
    int update(@Param("commentId") Integer commentId);

    @Results({
            @Result(property = "commentId",column = "comment_id"),
            @Result(property = "commentContent",column = "comment_content"),
            @Result(property = "orders",column = "comment_order_id",one = @One(select = "com.bishe.bishe.dao.mapper.OrderMapper.finddetailById")),
    })
    @Select("select * from comment c,feedback f where f.feedback_comment_id=c.comment_id and c.comment_order_id=#{orderId}")
    List<Comments> findByOrderId(@Param("orderId") Integer orderId);

    @Results({
            @Result(property = "commentId",column = "comment_id"),
            @Result(property = "commentContent",column = "comment_content"),
            @Result(property = "orders",column = "comment_order_id",one = @One(select = "com.bishe.bishe.dao.mapper.OrderMapper.finddetailById")),
    })
    @Select("select * from comment  where comment_state='未回复' ")
    List<Comments> findnumber();


}
